<?php
  //Loader::loadFile('config.php', 'modules/DeGIS');
  /**
  * initialise module
  *
  */
  function IShopUser_init() {

    if (!DBUtil::createTable('ishopuser_information')) {
        return false;
    }

    //Create upload module path   
    createIShopUserFolder();
    
    return true;
  }

  function IShopUser_delete() {
  
    Loader::loadFile('config.php', "modules/IShopUser");
      
    DBUtil::dropTable('ishopuser_information');    
    removeIShopUserFolder(UPLOAD_FILES_ISHOPUSER);
    
    return true;
  }




  function createIShopUserFolder(){
  
  
    Loader::loadFile('config.php', "modules/IShopUser");
    
    //Create root path
    if(!is_dir(UPLOAD_FILES_MAINPATH)){
      mkdir(UPLOAD_FILES_MAINPATH, 0777);
      
      //copy .htaccess and index.html into resource directory (root path)
      copy(HTACCESS_PATH, UPLOAD_FILES_MAINPATH_HTACCESS_PATH);
      copy(HTML_BLANK_PATH, UPLOAD_FILES_MAINPATH_HTML_BLANK_PATH);          
    }


    //Create gallery path
    if(!is_dir(UPLOAD_FILES_ISHOPUSER)){
      mkdir(UPLOAD_FILES_ISHOPUSER, 0777);
      
      //copy .htaccess and index.html into resource directory (root path)
      copy(HTACCESS_PATH, UPLOAD_FILES_ISHOPUSER_HTACCESS);
      copy(HTML_BLANK_PATH, UPLOAD_FILES_ISHOPUSER_BLANK_HTML);          
    }   
    

    //Create gallery path
    if(!is_dir(UPLOAD_FILES_ISHOPUSER_SHOPICON)){
      mkdir(UPLOAD_FILES_ISHOPUSER_SHOPICON, 0777);
      
      //copy .htaccess and index.html into resource directory (root path)
      copy(HTACCESS_PATH, UPLOAD_FILES_ISHOPUSER_SHOPICON_HTACCESS);
      copy(HTML_BLANK_PATH, UPLOAD_FILES_ISHOPUSER_SHOPICON_BLANK_HTML);          
    }  
     
  }
  
  
  function removeIShopUserFolder($dir){

    //Remove folder 
    if (!file_exists($dir)){ 
      return true; 
    }
    
    //Remove file
    if (!is_dir($dir) || is_link($dir)){
      return unlink($dir); 
    }
    
    //Recursive remove file & folder   
    foreach (scandir($dir) as $item) { 
        if ($item == '.' || $item == '..') continue; 
        if (!removeIShopUserFolder($dir . "/" . $item)) { 
            chmod($dir . "/" . $item, 0777); 
            if (!removeIShopUserFolder($dir . "/" . $item)) return false; 
        }; 
    } 
    rmdir($dir);   
  
  }